<?php 
/**
 * @author MarcusM. works for SunyardBPO. QQ:2453302174
 * 					Last updating at Dec 18, 2014. 
 */

class MyARedisHash extends ARedisHash
{
	public function set($key, $value)
	{
		if(is_object($value) || is_array($value)){
			$value = json_encode($value);
		}
		return $this->add($key, $value);
	}
	
	public function get($key)
	{
		if ($this->name === null){
			throw new CException(get_class($this)." requires a name!");
		}
		$ret = $this->getConnection()->getClient()->hget($this->name, $key);
		if($ret === false){
			return false;
		}else{
			return json_decode($ret);
		}
	}
	
	public function getAll($assoc = false)
	{
		$all = $this->getData();
		foreach($all as $k => $v){
			$decodedV = json_decode($v, $assoc);
			if($decodedV === null && $decodedV != $v){
				$decodedV = $v;
			}
			
			$all[$k] = $decodedV;
		}
		
		return $all;
	}
}